package easy

import (
	. "GoLeetcode/common"
)

/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */

/*
时间复杂度:O(N)
空间复杂度:O(N)
*/
func isUnivalTree(root *TreeNode) bool {
	if root == nil {
		return true
	}
	val := root.Val
	flag := true
	var dfs func(node *TreeNode)
	dfs = func(node *TreeNode) {
		if node == nil {
			return
		}
		if node.Val != val {
			flag = false
			return
		}
		dfs(node.Left)
		dfs(node.Right)
	}
	dfs(root)
	return flag
}
